# -*- coding:utf-8 -*-  
__author__ = 'Cullen, TenaciousZ'  
import os
import sys
path = os.path.abspath(os.path.join(__file__, "../.."))
sys.path.append(path)

from Tkinter import *  
from PIL import ImageTk, Image
from tkfuncs import MenuDIY, FrameDIY, get_file_list


class MyMenu(MenuDIY):
	def __init__(self, master):
		super(MyMenu, self).__init__(master)

	def init(self):
		self.menu_diy()

	def menu_diy(self):
		optionmenu = Menu(self.menubar, tearoff=1)  
		optionmenu.add_command(label='About', command=self.show_info)  
		optionmenu.add_command(label='Help', command=self.show_help)  
		optionmenu.add_separator()		# 横线
		optionmenu.add_command(label='Exit', command=self.master.destroy)  
		self.menubar.add_cascade(label='Options', menu=optionmenu)

class MyFrame(FrameDIY):
	def __init__(self):
		super(MyFrame, self).__init__()
		self.image_path = '../wifi.jpg'
		self.doc_path = '%s%sdoc%s' % (path, os.sep , os.sep)

	def init(self):
		self.left_frame_diy()
		self.right_frame_diy()
		self.text_frame_diy()

	def left_frame_diy(self):
		"""自定义左边表单"""
		self.left_frame = Frame()
		self.listbox = Listbox(self.left_frame, bg="#D6D6D6", 
								selectborderwidth=1, 
								selectbackground="#1979CA",  
								font=self.message_ft, 
								height=20, 
								width=30)
		scrollbar = Scrollbar(self.left_frame, orient=VERTICAL, bg='green')  
		scrollbar.config(command=self.listbox.yview)  
		scrollbar.pack(side=LEFT, fill=Y)  
		self.listbox.config(yscrollcommand=scrollbar.set)  
		self.listbox.pack(side=RIGHT, fill=BOTH, expand=1)

	def right_frame_diy(self): 
		"""自定义右下角文本表单"""
		self.right_frame = Frame()
		self.image = ImageTk.PhotoImage(file=self.image_path)
		button = Button(self.right_frame, image=self.image, command=self.get_entry_input)  
		button.pack(side=RIGHT, fill=X)  
	 
		self.entry = Entry(self.right_frame, bd=2, width=40, justify=RIGHT)  
		self.entry.pack(side=RIGHT, fill=X)  
		self.entry.bind('<Return>', self.get_input)

	def text_frame_diy(self):
		"""自定义右边表单"""
		self.text_frame = Frame()  
		scrollbar = Scrollbar(self.text_frame, orient=VERTICAL)  
		self.textarea = Text(self.text_frame, bg='#CCFFCC', width=90, height=30)

		scrollbar.config(command=self.textarea.yview)  
		scrollbar.pack(side=RIGHT, fill=Y)  
		self.textarea.config(yscrollcommand=scrollbar.set)  
		self.textarea.pack(side=LEFT, fill=BOTH, expand=1)

def main():  
	root = Tk()  
	root.title("Command Manual")  
	root.resizable(0,0)  
  
	menu = MyMenu(root)
	menu.init()
	root.config(menu=menu.menubar)

	my_frame = MyFrame()
	my_frame.init()

	left_frame = my_frame.left_frame
	left_frame.grid(row=0, column=0, rowspan=2, sticky=N+W+S+E)  
  
	right_frame = my_frame.right_frame
	right_frame.grid(row=0, column=1, sticky=N+W+E)  

	text_frame = my_frame.text_frame
	text_frame.grid(row=1,column=1, sticky=N+W+S+E )  

	#show the command list according the given path  
	doc_path = '%s%sdoc%s' % (path, os.sep , os.sep) 
	file_list = get_file_list(doc_path)  
  
	for item in file_list:  
		item = item.split('.')[0]  
		my_frame.listbox.insert(END, item)  

	root.mainloop()  
  

if __name__ == '__main__':  
	main()